package com.service.impl;

import com.bean.ActJoinInfo;
import com.bean.ActPic;
import com.bean.Activity;
import com.bean.Users;
import com.bean.vo.ActivityVo;
import com.bean.vo.UsersVo;
import com.mapper.ActJoinInfoMapper;
import com.mapper.ActPicMapper;
import com.mapper.ActivityMapper;
import com.mapper.UsersMapper;
import com.service.ActivityService;
import com.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ActivityServiceImpl implements ActivityService {

    @Autowired
    private ActivityMapper activityMapper;
    @Autowired
    private UsersMapper usersMapper;
    @Autowired
    private ActPicMapper actPicMapper;
    @Autowired
    private ActJoinInfoMapper actJoinInfoMapper;


    @Override
    @Transactional
    public int addActivity(Activity a,ActPic pic) {

      int i=  actPicMapper.insertSelective(pic);
      int j=  activityMapper.insertSelective(a);
      if(i==1&& j==1){
          return 1;
      }else{
          return 0;
      }
    }

    //查询所有活动，包含图片
    @Override
    public List<ActivityVo> selectActivityList(Activity a) {
        return activityMapper.selectList();
    }

    //查询单个活动详情，包含参加者
    @Override
    public ActivityVo checkOneActivity(Activity a) {
       List<ActivityVo>  activityVos=   activityMapper.selectContent(a);
       if(activityVos.size()>0 ){
         ActivityVo activityVo=   activityVos.get(0);
         Users u=new Users();
         u.setId(activityVo.getId());
         List<Users>users= usersMapper.selectUser(u);
         activityVo.setUsersList(users);
         return activityVo;
       }else{
         return null;
       }
    }

    @Override
    public int joinActivity(ActJoinInfo a) {
        return actJoinInfoMapper.insertSelective(a);
    }


}
